<template>
  <div id="user">
    <el-form label-width="80px" :model="user" style="width: 350px">
      <el-form-item label="姓名">
        <el-input v-model="user.name" placeholder="请输入姓名"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input
          type="pass"
          v-model="user.pass"
          placeholder="请输入密码"
        ></el-input>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="user.em" placeholder="请输入邮箱"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="submitForm(user)"
          >提交</el-button
        >
        <el-button size="mini" @click="resetForm(user)">重置</el-button>
      </el-form-item>
    </el-form>
    <template>
      <el-table :data="info" style="width: 100%">
        <el-table-column prop="name" label="姓名"> </el-table-column>
        <el-table-column prop="pass" label="密码"> </el-table-column>
        <el-table-column prop="em" label="邮箱"> </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="danger"
              size="mini"
              @click="deleteRow(scope.$index, info)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>
  </div>
</template>

<script>
export default {
  data() {
    return {
      user: {
        name: "",
        pass: "",
        em: "",
      },
      info: [
      ],
    };
  },
  methods: {
    // 添加
    submitForm(formName) {
      this.info.push(formName);
      this.user = {
        name: "",
        pass: "",
        em: "",
      };
    },
    // 重置
    resetForm() {
      this.user = {
        name: "",
        pass: "",
        em: "",
      };
    },
    // 删除
    deleteRow(index, rows) {
      rows.splice(index, 1);
    },
  },
};
</script>

<style lang="less" scoped>

</style>